#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT([DIMVisual (MPI-Rastro Data Source)],0.1,schnorr@gmail.com,dimvisual-mpirastro)

# Check for GNUstep
if test -z "$GNUSTEP_SYSTEM_ROOT"; then
	AC_MSG_ERROR([You must run the GNUstep.sh script before configuring])
fi

AC_CONFIG_AUX_DIR($GNUSTEP_MAKEFILES)

# Set location of GNUstep dirs for later use
GNUSTEP_HDIR=$GNUSTEP_SYSTEM_ROOT/Library/Headers
if test "$GNUSTEP_FLATTENED" = yes; then
  GNUSTEP_LDIR=$GNUSTEP_SYSTEM_ROOT/Library/Libraries
else
  clean_target_os=`$GNUSTEP_MAKEFILES/clean_os.sh $target_os`
  clean_target_cpu=`$GNUSTEP_MAKEFILES/clean_cpu.sh $target_cpu`
  obj_dir=$clean_target_cpu/$clean_target_os
  GNUSTEP_LDIR=$GNUSTEP_SYSTEM_ROOT/Library/Libraries/$obj_dir
fi

# Checks for programs.
AC_PROG_CC

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h stdlib.h string.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_HEADER_TIME

# Checks for library functions.
AC_FUNC_STRTOD
AC_CHECK_FUNCS([gettimeofday])

OUTPUTFILES="GNUmakefile"

AC_ARG_WITH(rastro-library,AS_HELP_STRING([--with-rastro-library=DIR],),,)
AC_ARG_WITH(rastro-include,AS_HELP_STRING([--with-rastro-include=DIR],),,)


#--------------------------------------------------------------------
# Verifying Paje Headers
#--------------------------------------------------------------------
AUX="-x objective-c"
AUX2="$CPPFLAGS -I$GNUSTEP_SYSTEM_ROOT/Library/Headers -I$GNUSTEP_LOCAL_ROOT/Library/Headers -I$HOME/GNUstep/Library/Headers/"
CPPFLAGS="$AUX $AUX2"
AC_CHECK_HEADERS(Paje/PajeEvent.h,,AC_MSG_ERROR([

   Paje headers not found. You can obtain a
   copy of it through this site:
   http://sourceforge.net/projects/libpaje/

   ]))
CPPFLAGS="$AUX2"

#--------------------------------------------------------------------
# Verifying Paje Library
#--------------------------------------------------------------------

LDFLAGS="$LDFLAGS -L$GNUSTEP_SYSTEM_ROOT/Library/Libraries/ -L$GNUSTEP_LOCAL_ROOT/Library/Libraries/ -L$HOME/GNUstep/Library/Libraries/ -lgnustep-base"
AC_CHECK_LIB(Paje,main,LIBS="$LIBS -lPaje",AC_MSG_ERROR([

   Paje library not found. You can obtain a
   copy of it throught this site:
   http://sourceforge.net/projects/libpaje/

   ]),)

#--------------------------------------------------------------------
# Verifying MPI-Rastro Headers
#--------------------------------------------------------------------
CPPFLAGS="$CPPFLAGS -I$with_rastro_include"
AC_CHECK_HEADER(rastro_public.h,,AC_MSG_ERROR([

   libRastro headers not found. You can provide
    a path to it through --with-rastro-include=DIR

    ]),)

#--------------------------------------------------------------------
# Verifying MPI-Rastro Library 
#--------------------------------------------------------------------
LDFLAGS="$LDFLAGS -L$with_rastro_library"
AC_CHECK_LIB(rastro,main,LIBS="$LIBS -lrastro",AC_MSG_ERROR([

   libRastro library not found. You can provide
    a path to it through --with-rastro-library=DIR

    ]),)


AC_SUBST(SUBPROJECTS_TO_COMPILE VERSION PACKAGE_TARNAME PACKAGE_VERSION)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)
AC_OUTPUT($OUTPUTFILES)

AC_MSG_NOTICE([

	Congratulations.
	* Be sure that a libPaje installation exists. If there is NOT such
	  installation, DIMVisual will not compile. Download libPaje from
	  http://sourceforge.net/projects/libpaje

	* DIMVisual is configured! Latest updates available at
	  http://sourceforge.net/projects/dimvisual

	* Type 'make' to compile and 'make install' to install
	])
